//
//  InteractionSectionHeaderView.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/19.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "InteractionSectionHeaderView.h"

@implementation InteractionSectionHeaderView

+(CGFloat)calculateHWithModel:(CommunityInteractionModel *)model {

    NSString *content = @"";
    
    if ([model.level isEqualToString:@"2"]) {
        content = model.commentContent;
    }
    
    if ([model.level isEqualToString:@"3"]) {
        content = model.replyContent;
    }
    
    if ([model.level isEqualToString:@"4"]) {
        content = model.replyNextContent;
    }
    
    CGFloat labHeight = [Utilities getStringHeightWithText:content font:[UIFont systemFontOfSize:14] viewWidth:(TTScreenWidth-78)];
    return 60 + labHeight + 10;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.height/2];
    });
}

- (void)fillWithModel:(CommunityInteractionModel *)model type:(CommunityInteractionListType)type {

    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:model.replyUserHeadUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.userName.text = model.replyUserNickName;
    
    
    NSString *postType;
    //类型（1：谈婚，2：论嫁，3：问答）必传
    switch (model.type) {
        case 1:{
            postType = @"帖子";
        } break;
        case 2:{
            postType = @"话题";
        } break;
        case 3:{
            postType = @"问答";
        } break;
        default:
            break;
    }
    
    switch (type) {
        case CommunityInteractionListType_eva:{

            
            //level为3的时候为60
            if ([model.level isEqualToString:@"2"]) {
                self.evaContentLab.text = model.commentContent;
                self.subTitleLab.text = [NSString stringWithFormat:@"回复了你的%@",postType];
            }
            
            //level为3的时候为60
            if ([model.level isEqualToString:@"3"]) {
                self.evaContentLab.text = model.replyContent;
                self.subTitleLab.text = [NSString stringWithFormat:@"回复了你的%@",@"评论"];
            }
            
            if ([model.level isEqualToString:@"4"]) {
                self.evaContentLab.text = model.replyNextContent;
                self.subTitleLab.text = [NSString stringWithFormat:@"回复了你的%@",@"评论"];
            }
            
        } break;
        case CommunityInteractionListType_thumb:{

            self.moreBtn.hidden = YES;
            self.evaContentLab.text = @"";
            
            if ([model.level isEqualToString:@"1"] || [model.level isEqualToString:@"2"]) {
                self.subTitleLab.text = [NSString stringWithFormat:@"赞了你的%@",postType];
            }
            
            //level为3的时候为60
            if ([model.level isEqualToString:@"3"] || [model.level isEqualToString:@"4"]) {
                self.subTitleLab.text = [NSString stringWithFormat:@"赞了你的%@",@"评论"];
            }
            
            
        } break;
        default:{
            
            self.evaContentLab.text = @"";
            self.subTitleLab.text = @"";
            
        } break;
    }
    
}

- (IBAction)actionBtn:(id)sender {
    if (self.InteractionSectionHeaderViewBlock) {
        self.InteractionSectionHeaderViewBlock();
    }
}


@end
